/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.lis.ctrl;

import com.cxhd.lis.model.newmodel.LisSampletype;
import static com.cxhd.lis.model.newmodel.LisSampletype.lisSampletypedao;
import com.jfinal.core.Controller;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import java.util.List;

/**
 *
 * @author cxhd
 */
@ControllerBind(controllerKey = "/view/lis/lisSam")
public class LisSampletypeCtrl extends Controller{
     public void index(){
        render("/view/lis/yblx.jsp");
    }
     public  void getLisSampletype(){
//        renderJson(Db.use("mysql").find("select * from lis_sampletype"));
        
         String sql="select PK,SAMPLEDESCRIBE,EXTENDTYPE,ZDM,PY,WB,TYPEORDER";
     String param=" from lis_sampletype where SAMPLEDESCRIBE like '%"+getPara("searchContent")+"%' or PY like '%"+getPara("searchContent")+"%'";
Page<Record> userPage = Db.use("mysql").paginate(getParaToInt("currentPage",getParaToInt("currentPage")), getParaToInt("pageSize",getParaToInt("pageSize")), sql, param);
renderJson(userPage);
     }
      public void addLisSampletype(){    
      new LisSampletype().saveLisSampletype( getPara("SAMPLEDESCRIBE"), 
              getPara("PY"), getPara("WB"));
       renderText("true");
    }
    public void updateLisSampletype(){
     new LisSampletype().updateLisSampletype(Integer.valueOf(getPara("PK")), getPara("SAMPLEDESCRIBE"), 
               getPara("PY"), getPara("WB"));
      renderText("true");
    }
    public void deleteLisSampletype(){
        lisSampletypedao.deleteLisSampletype(Integer.valueOf(getPara("PK")));
        renderText("true");
    }
    public void getLisSampletypeRep(){
        List<Record> list=Db.use("mysql").find("select * from lis_sampletype where  SAMPLEDESCRIBE='"+getPara("SAMPLEDESCRIBE")+"'" );
        if(list.size()!=0){
//            System.out.println(getPara("PK"));
//            System.out.println(list.get(0).get("PK"));
            if(getPara("PK")!=""&&getPara("PK")!=null){
            if(Integer.valueOf(getPara("PK"))==list.get(0).get("PK")){
                 renderText("false");
            }else{
               renderText("true");  
            }
            }else{
                renderText("true");
            }
        }else{
            renderText("false");
        }
                
    }
}
